# $Id$
# Maintainer: Alexander Baldeck <alexander@archlinux.org>
# Contributor: Jan de Groot <jgc@archlinux.org>
pkgname=xorg-xdm
pkgver=1.1.11+50+gb685338
pkgrel=1
pkgdesc="X Display Manager"
arch=(x86_64)
url="https://xorg.freedesktop.org/"
license=('custom')
depends=('pam' 'libxaw' 'libxinerama' 'xorg-xrdb' 'xorg-sessreg' 'libxft' 'systemd')
makedepends=('pkgconfig' 'xorg-util-macros' 'xtrans' git autoconf-archive)
backup=(etc/X11/xdm/Xaccess etc/X11/xdm/Xresources etc/X11/xdm/Xservers etc/X11/xdm/xdm-config etc/pam.d/xdm etc/X11/xdm/Xsetup_0 etc/X11/xdm/Xsession)
_commit=b6853380678b793bad81ac09b2f872f8225ccec6  # master
source=("git+https://anongit.freedesktop.org/git/xorg/app/xdm#commit=$_commit"
        Xsession-loginshell.patch
        Xsession-xsm.patch
        xdm-1.0.5-sessreg-utmp-fix-bug177890.patch
        xdm.pam
        libsystemd.patch
        nolisten.patch)
sha512sums=('SKIP'
            '4777e227c99bd39409a134fc2b0cb6ffd8f80ad0e0106ee9ab172637fdafe85027fe05ad7fc978005473ef683ab92f52d3cf06a257991af6b1aeaefe9860953e'
            'eba7a9edfbbd9a9c7a0566b9b8a436e1eb9271d4e26f6200c53b70ab392d358191fd37c831aad8f94a9a6710f9ec66ee1f34adadb7ba121e55aee6a84b2ea32f'
            '698d401899660708dc17eaa84bd2323426afa4c3c094ff8d4a8d9c54e26e073f40dafed67636855bb230f351523a88f1f1ed1ec443d77d92ef65646b5a6976d5'
            'cb912013a294f0801b357a43f3e5313ffa9ac5fcc493b2318843983388eb0b839c84060a97c355e12ca03f3b056644aa4a2bb8a74ed73a0f2405816b8d6efdc0'
            'f30243aa8343d245e32a80953dc990d95d0b9048574a1ae777cb81cde14a0e167e544df1d40d7316ec8465571bd6b68cda984bb40c1fe99fc7ce348247cdca71'
            'e21a7a9d0f6fa89146ad86e0083f4fe5d6451fe6f69c4ebe1e4f72507ac4f4c4cb0c4055679cb5d32d197c9f658a02ef2748c1357e6264c40fa122adb8ecd766')

pkgver() {
  cd xdm
  git describe --tags | sed 's/^xdm-//;s/-/+/g'
}

prepare() {
  cd xdm
  patch -Np0 -i "${srcdir}/Xsession-loginshell.patch"
  patch -Np1 -i "${srcdir}/Xsession-xsm.patch"
  patch -Np0 -i "${srcdir}/xdm-1.0.5-sessreg-utmp-fix-bug177890.patch"
  patch -Np1 -i ../nolisten.patch
  patch -Np1 -i ../libsystemd.patch
  NOCONFIGURE=1 ./autogen.sh
}

check() {
  cd xdm
  make check
}

build() {
  cd "${srcdir}/xdm"

  autoreconf -fi
  ./configure --prefix=/usr \
      --disable-xdm-auth \
      --disable-static \
      --with-xdmconfigdir=/etc/X11/xdm \
      --with-xdmscriptdir=/etc/X11/xdm \
      --with-pixmapdir=/usr/share/xdm/pixmaps

  sed -i -e 's/ -shared / -Wl,-O1,--as-needed\0/g' libtool

  make
}

package() {
  cd "${srcdir}/xdm"
  make DESTDIR="${pkgdir}" install
  install -m755 -d "${pkgdir}/var/lib/xdm"
  install -m755 -d "${pkgdir}/etc/pam.d"
  install -m644 "${srcdir}/xdm.pam" "${pkgdir}/etc/pam.d/xdm"
  install -m755 -d "${pkgdir}/usr/share/licenses/${pkgname}"
  install -m644 COPYING "${pkgdir}/usr/share/licenses/${pkgname}/"

  sed -i -e 's/\/X11R6//g' "${pkgdir}"/etc/X11/xdm/*

  sed -i 's|^Alias=.*|Alias=display-manager.service|' \
    "$pkgdir/usr/lib/systemd/system/xdm.service"
}
